<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<div id="app">
			
			<com1></com1>
			
			<com2></com2>
			
		</div>
	</body>
	<script src="vue.js"></script>
	<script>
	
		var bus = new Vue();
	
		Vue.component("com1",{
			template:"<button @click='btnClick'>显示</button>",
			methods:{
				btnClick:function(){
					bus.$emit("givemsg","你好");
				}
			}
		});
		
		Vue.component("com2",{
			template:"<p>{{txt}}</p>",
			data:function(){
				return {
					txt:""
				}
			},
			created:function(){
				bus.$on("givemsg",function(d){
					this.txt = d;
				}.bind(this));
			}
		});
	
	
		var app = new Vue({
			el:"#app",
			data:{
				
			}
		});
	</script>
</html>
